home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jedit_checkpoint.tcl < prev    next >
Encoding:
Text File  |  1995-02-08  |  2.5 KB  |  78 lines

  1. # jedit_checkpoint.tcl - undo and redo support for jedit
  2. # Copyright 1992-1994 by Jay Sekora.  All rights reserved, except 
  3. # that this file may be freely redistributed in whole or in part 
  4. # for non-profit, noncommercial use.
  5.  
  6. ######################################################################
  7. # save current state in undo ring
  8. #   { t args } lets it be used with j:tkb:mkmap
  9. ######################################################################
  10.  
  11. proc jedit:cmd:save_checkpoint { t args } {
  12.   global CKPT_TEXT CKPT_ANNO JEDIT_PREFS UNDOPTR
  13.  
  14.   if $JEDIT_PREFS(undolevels) {
  15.     set CKPT_TEXT($UNDOPTR) [$t get 1.0 end]
  16.     set CKPT_ANNO($UNDOPTR) [j:tag:get_annotation $t]
  17.     incr UNDOPTR
  18.     set old [expr {$UNDOPTR - $JEDIT_PREFS(undolevels)}]
  19.     catch {
  20.       unset CKPT_TEXT($old)            ;# forget a previous checkpoint
  21.       unset CKPT_ANNO($old)
  22.     }
  23.   } else {
  24.     j:alert -text "You don't have undo turned on."
  25.   }
  26. }
  27.  
  28. ######################################################################
  29. # jedit:cmd:undo - restore from saved state (moving backwards in undo ring)
  30. #   { t args } lets it be used with j:tkb:mkmap
  31. ######################################################################
  32.  
  33. proc jedit:cmd:undo { t args } {
  34.   global CKPT_TEXT CKPT_ANNO JEDIT_PREFS UNDOPTR
  35.  
  36.   if $JEDIT_PREFS(undolevels) {
  37.     set CKPT_TEXT($UNDOPTR) [$t get 1.0 end]
  38.     set CKPT_ANNO($UNDOPTR) [j:tag:get_annotation $t]
  39.     incr UNDOPTR -1
  40.     if {![info exists CKPT_TEXT($UNDOPTR)]} {
  41.       incr UNDOPTR
  42.       j:alert -text "No more undo information available."
  43.     }
  44.     $t delete 1.0 end
  45.     $t insert end $CKPT_TEXT($UNDOPTR)
  46.     j:tag:set_annotation $t $CKPT_ANNO($UNDOPTR)
  47.     $t yview -pickplace insert
  48.   } else {
  49.     j:alert -text "You aren't saving any undo information."
  50.   }
  51. }
  52.  
  53. ######################################################################
  54. # restore from saved state (moving forwards in undo ring)
  55. #   { t args } lets it be used with j:tkb:mkmap
  56. ######################################################################
  57.  
  58. proc jedit:cmd:redo { t args } {
  59.   global CKPT_TEXT CKPT_ANNO JEDIT_PREFS UNDOPTR
  60.  
  61.   if $JEDIT_PREFS(undolevels) {
  62.     set CKPT_TEXT($UNDOPTR) [$t get 1.0 end]
  63.     set CKPT_ANNO($UNDOPTR) [j:tag:get_annotation $t]
  64.     incr UNDOPTR
  65.     if {![info exists CKPT_TEXT($UNDOPTR)]} {
  66.       incr UNDOPTR -1
  67.       j:alert -text "No more redo information available."
  68.     }
  69.     $t delete 1.0 end
  70.     $t insert end $CKPT_TEXT($UNDOPTR)
  71.     j:tag:set_annotation $t $CKPT_ANNO($UNDOPTR)
  72.     $t yview -pickplace insert
  73.   } else {
  74.     j:alert -text "You aren't saving any undo information."
  75.   }
  76. }
  77.